import {
  HTTP
}
from '../util/http.js'

class ClassicModel extends HTTP {
  getLatest(sCallback) {
    this.request({
      url: '/classic/latest',
      success: (res) => {
        sCallback(res)
        this._setLatestIndex(res.index)
        let key = this._getKey(res.index)
        wx.setStorageSync(key, res)
      }
    })
  }
  _setLatestIndex(index) {
    wx.setStorageSync('latest', index)
  }
  _getKey(index) {
    const key = 'classic-' + index
    return key
  }
  getPrevious(index, sCallback) {
    this.request({
      url: `/classic/${index}/previous`,
      success: (res) => {
        sCallback(res)
      }
    })
  }
  isFirst(index) {
    return index == 1 ? true : false
  }

  isLatest(index) {
    let latestIndex = this._getLatestIndex()
    return latestIndex == index ? true : false
  }

  _getLatestIndex() {
    const index = wx.getStorageSync('latest')
    return index
  }
}



export {
    ClassicModel
}